package com.czy.owner.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.entity.HomeServiceModel;
import com.czy.owner.entity.ShoppingModel;
import com.czy.owner.utils.glide.GlideUtils;
import com.czy.owner.widget.RoundImageView;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;


/**
 * Created by asus on 2017/5/9.
 */
public class HomeServiceAdapter extends RecyclerArrayAdapter<ShoppingModel.ModelsListBean> {
    private Context context;
    public HomeServiceAdapter(Context context) {
        super(context);
        this.context=context;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new HomeServiceHolder(parent);
    }

    class HomeServiceHolder extends BaseViewHolder<ShoppingModel.ModelsListBean> {
        private RoundImageView ivServiceImg;
        private TextView tvServiceName;

        public HomeServiceHolder(ViewGroup parent) {
            super(parent, R.layout.item_shopping_service);
            ivServiceImg = $(R.id.iv_service_img);
            tvServiceName = $(R.id.tv_service_name);
        }

        @Override
        public void setData(ShoppingModel.ModelsListBean model) {
            super.setData(model);
            if (model.getType()!=0){
                ivServiceImg.setImageResource(R.mipmap.icon_home_more);
            }
            else {
                GlideUtils.loadImage(context,model.getModelsLogo(), ivServiceImg, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                    @Override
                    public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                    }

                    @Override
                    public void onLoadingError(String source, Exception e) {

                    }
                },R.mipmap.default_icon,R.mipmap.default_icon);
            }

            tvServiceName.setText(model.getModelsName());
        }
    }

}
